/**
 * 
 */
package kr.co.insoft.auth.service.codec.impl;

import kr.co.insoft.auth.mapper.codec.WeeklyCodecKeyMapper;
import kr.co.insoft.auth.service.codec.WeeklyCodecKeyService;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.ServiceException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Service
public class WeeklyCodecKeyServiceImpl implements WeeklyCodecKeyService {

	@Autowired
	WeeklyCodecKeyMapper mapper;

	public String getSalt() throws ServiceException {
		try {
			String salt = mapper.getSalt();
			Assert.notNull(salt);
			return salt;
		} catch (IllegalArgumentException e) {
			try {
				mapper.updateWeeklyCodecKey();
				return mapper.getSalt();
			} catch (Exception e2) {
				throw new ServiceException(ExceptionCode.SERVICE_EXCEPTION, e);
			}
		} catch (Exception e) {
			throw new ServiceException(ExceptionCode.SERVICE_EXCEPTION, e);
		}
	}
}
